package com.skyable.auth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.skyable.auth.entity.SysPermission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author GaoYuan
 * @date 2020/10/23 9:42
 * @desc
 */
@Mapper
public interface PermissionMapper extends BaseMapper<SysPermission> {

    /**
     * 根据用户名查询权限信息
     * @param userName
     * @return
     */
    @Select("SELECT p.* FROM sys_user u LEFT JOIN sys_user_role ur ON u.id = ur.user_id LEFT JOIN sys_role_permission rp ON ur.role_id = rp.role_id LEFT JOIN sys_permission p ON rp.permission_id = p.id WHERE u.username = #{userName}")
    List<SysPermission> findPermissionByUserName(@Param("userName") String userName);

}
